idx=1; sum1=0
while idx <= 100:
    sum1 += idx
    idx += 1
print(sum1) # 5050 = ( 1+100 ) * 50

idx=1; sum1=0
while idx <= 100:
    sum1 += idx
    idx += 1
    if idx > 50: break
# 最后，穷尽之后，也会执行一次
else:
    print('idx=',idx)   # 101
print('sum1=', sum1)

# 只有一句，可以写在一行里面
int1=3
while int1:=int1-1: print('int1=', int1)

# for 针对 容器，序列，总而言之，任意的可迭代类型
str1 = 'string'
# for s in str1: print(s)
for s in str1: 
    print(s)
else:
    print(s, '是最后一个了')

# break 会跳出，并且无视else(while也一样)
for s in str1: 
    print(s)
    if s == 'i': break
else:
    print(s, '是最后一个了')

# continue, while也一样
for s in str1:
    if s == 'i': continue 
    print(s)

# pass: 保持程序结构的完整, 自身无意义
# 因为没有内容的话，报错
for s in str1:
    print(s, '之前')
    pass
    print(s, '之后')

print('-------------------------------')

# 带 索引项
for i in enumerate(str1): print(i)
'''
(0, 's')
(1, 't')
(2, 'r')
(3, 'i')
(4, 'n')
(5, 'g')
'''
for i, j in enumerate(str1): print(i, j)
'''
0 s
1 t
2 r
3 i
4 n
5 g
'''

# 嵌套
for i in range(1,6):
   for j in range(1, i+1):
      print("*",end='')
   print('\r')

# 快速求和
print(sum(range(101)))